﻿/*+===================================================================
File:      StoneFlying.cpp

Summary:   Định nghĩa các phương thức của CStoneFlying.
===================================================================+*/

#include "StoneFlying.h"

#define LIMIT_DISTANCE 180

CStoneFlying::CStoneFlying(D3DXVECTOR2 pos, int id, int typeID) : CMoveableObject(pos, id, typeID)
{
	CResourcesManager::GetInstance()->GetSprite(ID_SPRITE_STONE_FLYING);
	m_pSprite = m_pResourceManager->GetSprite(ID_SPRITE_STONE_FLYING);

	m_v.x = -100.0f;
	m_limitX1 = m_pos.x - LIMIT_DISTANCE;
	m_limitX2 = m_pos.x;

	m_box.width = 64;
	m_box.height = 18;
}


CStoneFlying::~CStoneFlying()
{

}

void CStoneFlying::Update(float timeFrame)
{
	if (!m_bIsLive)
		return;

	m_pos += m_v* timeFrame;

	if (m_pos.x < m_limitX1)
	{
		m_pos.x = m_limitX1;
		m_v.x *= -1;
	}
	else if (m_pos.x > m_limitX2)
	{
		m_pos.x = m_limitX2;
		m_v.x *= -1;
	}
		
	UpdateBox(timeFrame);
}

void CStoneFlying::UpdateBox(float timeFrame)
{
	m_box.x = m_pos.x - m_pSprite->GetWidth() / 2.0f;
	m_box.y = m_pos.y + m_pSprite->GetHeight() / 2.0f - 12.0f;
	m_box.vX = m_v.x;
	m_box.vY = m_v.y;
}